home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / smix130.zip / DETECT.PAS next >
Pascal/Delphi Source File  |  1997-06-06  |  3KB  |  79 lines

  1. {       SMIX is Copyright 1995 by Ethan Brodsky.  All rights reserved.       }
  2. unit Detect;
  3.   interface
  4.     function GetSettings
  5.      (
  6.       var BaseIO : word;
  7.       var IRQ    : byte;
  8.       var DMA    : byte;
  9.       var DMA16  : byte
  10.      ): boolean;
  11.       {Gets sound card settings from BLASTER environment variable            }
  12.       {Parameters:                                                           }
  13.       {  BaseIO:  Sound card base IO address                                 }
  14.       {  IRQ:     Sound card IRQ                                             }
  15.       {  DMA:     Sound card 8-bit DMA channel                               }
  16.       {  DMA16:   Sound card 16-bit DMA channel (0 if none)                  }
  17.       {Returns:                                                              }
  18.       {  TRUE:    Sound card settings found successfully                     }
  19.       {  FALSE:   Sound card settings could not be found                     }
  20.  
  21.   implementation
  22.     uses
  23.       DOS;
  24.     function UpcaseStr(Str: string): string;
  25.       var
  26.         i: byte;
  27.         Temp: string;
  28.       begin
  29.         Temp[0] := Str[0];
  30.         for i := 1 to Length(Str) do
  31.           Temp[i] := Upcase(Str[i]);
  32.         UpcaseStr := Temp;
  33.       end;
  34.     function GetSetting(Str: string; ID: char; Hex: boolean): word;
  35.       var
  36.         Temp : string;
  37.         Num  : word;
  38.         Code : integer;
  39.       begin
  40.         Temp := Str;
  41.         if Pos(ID, Temp) <> 0
  42.           then
  43.             begin
  44.               Delete(Temp, 1, Pos(ID, Temp));
  45.               Delete(Temp, Pos(' ', Temp), 255);
  46.               if Hex then Insert('$', Temp, 1);
  47.               Val(Temp, Num, Code);
  48.               if Code = 0
  49.                 then GetSetting := Num
  50.                 else GetSetting := $FF;
  51.             end
  52.           else
  53.             GetSetting := $FF;
  54.  
  55.       end;
  56.     function GetSettings
  57.      (
  58.       var BaseIO: word;
  59.       var IRQ: byte;
  60.       var DMA: byte;
  61.       var DMA16: byte
  62.      ): boolean;
  63.       var
  64.         BLASTER: string;
  65.       begin
  66.         BLASTER := UpcaseStr(GetEnv('BLASTER'));
  67.         BaseIO := GetSetting(BLASTER, 'A', true);  {Hex}
  68.         IRQ    := GetSetting(BLASTER, 'I', false); {Decimal}
  69.         DMA    := GetSetting(BLASTER, 'D', false); {Decimal}
  70.         DMA16  := GetSetting(BLASTER, 'H', false); {Decimal}
  71.  
  72.         GetSettings := true;
  73.         if BLASTER = ''  then GetSettings := false;
  74.         if BaseIO  = $FF then GetSettings := false;
  75.         if IRQ     = $FF then GetSettings := false;
  76.         if DMA     = $FF then GetSettings := false;
  77.         {We can survive if there isn't a DMA16 channel}
  78.       end;
  79.   end.